package com.hgkj.cloud.base.common;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * app返回结果
 * 
 * 
 */
public class ResponseData implements Serializable{

	/**
	 * 1表示成功，其他值表示失败
	 */
	private int code = 1;// 1表示成功，其他值表示失败
	/**
	 * 提示信息
	 */
	private String msg = "操作成功";// 提示信息
	/**
	 * 数据
	 */
	private Map<String, Object> data = null;// 数据

	public ResponseData(int code, String msg, Map<String, Object> data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public ResponseData() {

	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Map<String, Object> getData() {
		return data;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}

	public void setDataPageInfo(PageInfo pi) {
		if (this.data == null) {
			this.data = new HashMap<>();
		}
		this.data.put("page", pi.getCurrentPage());
		this.data.put("page_size", pi.getPageSize());
	}

	public static ResponseData getResult(Integer code, String msg) {
		return getResult(new HashMap<>(), code, msg);
	}

	public static ResponseData getResult(Map<String, Object> resultMap, Integer code, String msg) {
		ResponseData retData = new ResponseData();
		retData.setData(resultMap);
		if (code != null) {
			retData.setCode(code);
		}
		if (msg != null) {
			retData.setMsg(msg);
		}
		return retData;
	}

	public static ResponseData getResult(Map<String, Object> resultMap) {
		return getResult(resultMap, null, null);
	}

	public static ResponseData getDefaultResult() {
		return getResult(new HashMap<>(), null, null);
	}
}
